package com.hen.web.henweb.common;

import com.hen.web.henweb.model.enumeration.StatusMsgEnum;
import lombok.Data;

/**
 * @author 狠穿
 * @version 1.0.0
 * @date 2023/3/15
 * @function 返回给前端的响应对象
 */
@Data
public class R {
    private Integer code;
    private String msg;
    private Object data;

    public R(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public R(Integer code, Object data) {
        this.code = code;
        this.data = data;
    }

    public R setCode(Integer code) {
        this.code = code;
        return this;
    }

    public R setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public R setData(Object data) {
        this.data = data;
        return this;
    }

    public static R succ(String msg){
        return new R(200,msg);
    }

    public static R succ(Object data){
        return new R(200,data);
    }

    public static R fail(String msg){
        return new R(400,msg);
    }

    public static R fail(Object data){
        return new R(400,data);
    }

    public static R succ(StatusMsgEnum statusMsgEnum){
        return new R(statusMsgEnum.getCode(),statusMsgEnum.getMsg());
    }

    public static R fail(StatusMsgEnum statusMsgEnum){
        return new R(statusMsgEnum.getCode(),statusMsgEnum.getMsg());
    }
}
